<?php
// If you believe in a god, pray to him that he forgive me for this hack.
$oClientgroups = ClientHandler::getClientgroups();
$iOne = 0;
if (count($oClientgroups) == 1) {
	foreach ($oClientgroups as $iID => $oThisClientgroup) {
		$oClients = ClientHandler::getClients($iID);
		if (count($oClients) == 1) {
			foreach ($oClients as $iClient => $oThisClient) {
				$iOneClientgroup = $iID;
				$iOneClient = $iClient;
			}
		}
	}
}

if ($iOneClient) {
	$oClients = ClientHandler::getClients($iOneClientgroup);
	foreach ($oClients as $iClient => $oThisClient) {
		$_REQUEST['iClientgroup'] = @$iClientgroup;
		$_REQUEST['iClient'] = $iClient;
		loadBox('time-add_final');
	}
}
else {
	?>
	<div id="layer_time_add" class="hidden" style="visibility: visible;">
	<table class="boxborder" cellspacing="0">
		<tr>
			<td class="boxhandle"><?php print msg('Select clientlist') ?></td>
		</tr>
	<?php
	foreach ($oClientgroups as $iID => $oThisGroup) {
		?>
		<tr>
			<td class="separator"><a href="javascript: togglePiece('time-add_clients', 'sView=<?php print $_REQUEST['sView'] ?>&iClientgroup=<?php print $iID ?>&iJob=<?php print $_REQUEST['iJob'] ?>&iMissionID=<?php print $_REQUEST['iMissionID'] ?>', 'time_clientlist_<?php print $iID ?>');"><?php print $oThisGroup->sName ?></a></td>
		</tr>
		<?php
		if (count($oClientgroups) == 1) {
			?>
			<tr>
				<td class="clear"><?php loadBox('time-add_clients', 'iClientgroup='.$iID) ?></td>
			</tr>
			<?php
		}
		else {
			?>
			<tr id="elf_time_clientlist_<?php print $iID ?>" style="display: none;">
				<td class="clear"><div id="time_clientlist_<?php print $iID ?>"></div></td>
			</tr>
			<?php
		}
	}
	?>
		<tr>
			<td class="boxbody center">
				<input type="button" value="<?php print msg('Cancel') ?>" onClick="layerHide('layer_time_add');">
			</td>
		</tr>
	</table>
	</div>
	<?php
}
?>
